package com.zee.wechat.framework.utils;


import com.zee.wechat.module.menu.entity.SysMenu;
import com.zee.wechat.module.sys.entity.UserInfo;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 获取当前登录用户工具类
 *
 * @author Zee
 * @date 2019年6月25日
 * @since v1.0
 */
@Component
public class UserUtil {
    public static UserInfo getUser() {
        return (UserInfo) UserUtil.getSession().getAttribute("sys");
    }

    public static void setUserSession(UserInfo user) {
        UserUtil.getSession().setAttribute("sys", user);
    }

    public static List<SysMenu> getMenuSession() {
        return (List<SysMenu>) UserUtil.getSession().getAttribute("menu");
    }

    public static void setMenuSession(List<SysMenu> menus) {
        UserUtil.getSession().setAttribute("menu", menus);
    }

    public static Session getSession() {
        Subject currentUser = SecurityUtils.getSubject();
        return currentUser.getSession();
    }


}
